package tagcloud.component;

import java.awt.Point;

public class Vector {

    Point P1;
    Point P2;

    public Vector(double x, double y) {
        P1 = new Point(0, 0);
        P2 = new Point((int)x, (int)y);
    }

    public Vector(Point P1, Point P2) {
        this.P1 = new Point(P1);
        this.P2 = new Point(P2);
    }

    public int deltaX() {
        return P2.x - P1.x;
    }

    public int deltaY() {
        return P2.y - P1.y;
    }

    public double length() {
        double dx = (P2.x - P1.x);
        double dy = (P2.y - P1.y);
        return Math.sqrt(dx * dx + dy * dy);
    }

    public double getPhi() {
        double dx = (P2.x - P1.x);
        double dy = (P2.y - P1.y);
        if (dx == 0) {
            return Math.PI / 2;
        } else {
            return Math.atan(dy / dx);
        }
    }

    public Vector add(Vector v) {
        return new Vector(P1, new Point(P2.x + (v.P2.x - v.P1.x), P2.y + (v.P2.y - v.P1.y)));
    }

    public Vector getOposite() {
        return new Vector(P1, new Point(2 * P1.x - P2.x, 2 * P1.y - P2.y));
    }
}
